package edu.ccut.saturn.common;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Dictionary;
import java.util.Enumeration;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;

import junit.framework.TestCase;

/**
 * 通过OSGiMockTestCase来封装常用测试方法及变量
 * 通过模拟实现接口Bundle, 以Class.forName的方式实现Bundle.loadClass方法
 * 
 * @author LeslieGu
 */
public class OSGiMockTestCase extends TestCase {

	public Bundle bundle = null;

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		this.bundle = new MockBundle();
	}

	private class MockBundle implements Bundle {

		private String bundleName = "test";

		public Enumeration<?> findEntries(String arg0, String arg1, boolean arg2) {
			return null;
		}

		public BundleContext getBundleContext() {
			return null;
		}

		public long getBundleId() {
			return 0;
		}

		public URL getEntry(String arg0) {
			return null;
		}

		public Enumeration<String> getEntryPaths(String arg0) {
			return null;
		}

		public Dictionary<?, ?> getHeaders() {
			return null;
		}

		public Dictionary<?, ?> getHeaders(String arg0) {
			return null;
		}

		public long getLastModified() {
			return 0;
		}

		public String getLocation() {
			return null;
		}

		public ServiceReference[] getRegisteredServices() {
			return null;
		}

		public URL getResource(String arg0) {
			return null;
		}

		public Enumeration<?> getResources(String arg0) throws IOException {
			return null;
		}

		public ServiceReference[] getServicesInUse() {
			return null;
		}

		public int getState() {
			return 0;
		}

		public String getSymbolicName() {
			return this.bundleName;
		}

		public boolean hasPermission(Object arg0) {
			return false;
		}

		public Class<?> loadClass(String arg0) throws ClassNotFoundException {
			return Class.forName(arg0);
		}

		public void start() throws BundleException {
			
		}

		public void stop() throws BundleException {
			
		}

		public void uninstall() throws BundleException {
			
		}

		public void update() throws BundleException {
			
		}

		public void update(InputStream arg0) throws BundleException {
			
		}

		public void start(int options) throws BundleException {
			// TODO Auto-generated method stub
			
		}

		public void stop(int options) throws BundleException {
			// TODO Auto-generated method stub
			
		}
	}
}
